home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / lang / fpcsrc.lha / fpc / compiler / m68k.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-24  |  61KB  |  1,738 lines

  1. {
  2.     $Id: m68k.pas,v 1.1.1.1.2.1 1998/08/13 17:41:24 florian Exp $
  3.     Copyright (c) 1995-98 by Florian Klaempfl, Carl Eric Codere
  4.  
  5.     This unit implements an types and classes specific for the
  6.     MC68000/MC68020
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  ****************************************************************************
  23. }
  24. unit m68k;
  25.  
  26.   interface
  27.  
  28.     uses
  29.        strings,systems,cobjects,globals,aasm,verbose;
  30.  
  31.     const
  32.       { if real fpu is used }
  33.       { otherwise maps to   }
  34.       { s32real.            }
  35.       extended_size = 12;
  36.  
  37.  
  38.     type
  39.     {  warning: CPU32 opcodes are not fully compatible with the MC68020. }
  40.        { 68000 only opcodes }
  41.        tasmop = (A_ABCD,
  42.          A_ADD,A_ADDA,A_ADDI,A_ADDQ,A_ADDX,A_AND,A_ANDI,
  43.          A_ASL,A_ASR,A_BCC,A_BCS,A_BEQ,A_BGE,A_BGT,A_BHI,
  44.          A_BLE,A_BLS,A_BLT,A_BMI,A_BNE,A_BPL,A_BVC,A_BVS,
  45.          A_BCHG,A_BCLR,A_BRA,A_BSET,A_BSR,A_BTST,A_CHK,
  46.          A_CLR,A_CMP,A_CMPA,A_CMPI,A_CMPM,A_DBCC,A_DBCS,A_DBEQ,A_DBGE,
  47.          A_DBGT,A_DBHI,A_DBLE,A_DBLS,A_DBLT,A_DBMI,A_DBNE,A_DBRA,
  48.          A_DBPL,A_DBT,A_DBVC,A_DBVS,A_DBF,A_DIVS,A_DIVU,
  49.          A_EOR,A_EORI,A_EXG,A_ILLEGAL,A_EXT,A_JMP,A_JSR,
  50.          A_LEA,A_LINK,A_LSL,A_LSR,A_MOVE,A_MOVEA,A_MOVEI,A_MOVEQ,
  51.          A_MOVEM,A_MOVEP,A_MULS,A_MULU,A_NBCD,A_NEG,A_NEGX,
  52.          A_NOP,A_NOT,A_OR,A_ORI,A_PEA,A_ROL,A_ROR,A_ROXL,
  53.          A_ROXR,A_RTR,A_RTS,A_SBCD,A_SCC,A_SCS,A_SEQ,A_SGE,
  54.          A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,A_SNE,
  55.          A_SPL,A_ST,A_SVC,A_SVS,A_SF,A_SUB,A_SUBA,A_SUBI,A_SUBQ,
  56.          A_SUBX,A_SWAP,A_TAS,A_TRAP,A_TRAPV,A_TST,A_UNLK,
  57.          A_RTE,A_RESET,A_STOP,
  58.          { MC68010 instructions }
  59.          A_BKPT,A_MOVEC,A_MOVES,A_RTD,
  60.          { MC68020 instructions }
  61.          A_BFCHG,A_BFCLR,A_BFEXTS,A_BFEXTU,A_BFFFO,
  62.          A_BFINS,A_BFSET,A_BFTST,A_CALLM,A_CAS,A_CAS2,
  63.          A_CHK2,A_CMP2,A_DIVSL,A_DIVUL,A_EXTB,A_PACK,A_RTM,
  64.          A_TRAPCC,A_TRACS,A_TRAPEQ,A_TRAPF,A_TRAPGE,A_TRAPGT,
  65.          A_TRAPHI,A_TRAPLE,A_TRAPLS,A_TRAPLT,A_TRAPMI,A_TRAPNE,
  66.          A_TRAPPL,A_TRAPT,A_TRAPVC,A_TRAPVS,A_UNPK,
  67.          { FPU Processor instructions - directly supported only. }
  68.          { IEEE aware and misc. condition codes not supported   }
  69.          A_FABS,A_FADD,
  70.          A_FBEQ,A_FBNE,A_FBNGT,A_FBGT,A_FBGE,A_FBNGE,
  71.          A_FBLT,A_FBNLT,A_FBLE,A_FBGL,A_FBNGL,A_FBGLE,A_FBNGLE,
  72.          A_FDBEQ,A_FDBNE,A_FDBGT,A_FDBNGT,A_FDBGE,A_FDBNGE,
  73.          A_FDBLT,A_FDBNLT,A_FDBLE,A_FDBGL,A_FDBNGL,A_FDBGLE,A_FBDNGLE,
  74.          A_FSEQ,A_FSNE,A_FSGT,A_FSNGT,A_FSGE,A_FSNGE,
  75.          A_FSLT,A_FSNLT,A_FSLE,A_FSGL,A_FSNGL,A_FSGLE,A_FSNGLE,
  76.          A_FCMP,A_FDIV,A_FMOVE,A_FMOVEM,
  77.          A_FMUL,A_FNEG,A_FNOP,A_FSQRT,A_FSUB,A_FSGLDIV,
  78.          A_FSFLMUL,A_FTST,
  79.          A_FTRAPEQ,A_FTRAPNE,A_FTRAPGT,A_FTRAPNGT,A_FTRAPGE,A_FTRAPNGE,
  80.          A_FTRAPLT,A_FTRAPNLT,A_FTRAPLE,A_FTRAPGL,A_FTRAPNGL,A_FTRAPGLE,A_FTRAPNGLE,
  81.          { Protected instructions }
  82.          A_CPRESTORE,A_CPSAVE,
  83.          { FPU Unit protected instructions                    }
  84.          { and 68030/68851 common MMU instructions            }
  85.          { (this may include 68040 MMU instructions)          }
  86.          A_FRESTORE,A_FSAVE,A_PFLUSH,A_PFLUSHA,A_PLOAD,A_PMOVE,A_PTEST,
  87.          { Useful for assembly langage output }
  88.          A_LABEL,A_NONE);
  89.  
  90.        { enumeration for registers, don't change the }
  91.        { order of this table                         }
  92.        { Registers which can and will be used by the compiler }
  93.        tregister = (
  94.          R_NO,R_D0,R_D1,R_D2,R_D3,R_D4,R_D5,R_D6,R_D7,
  95.          R_A0,R_A1,R_A2,R_A3,R_A4,R_A5,R_A6,R_SP,
  96.          { PUSH/PULL- quick and dirty hack }
  97.          R_SPPUSH,R_SPPULL,
  98.          { misc. }
  99.          R_CCR,R_FP0,R_FP1,R_FP2,R_FP3,R_FP4,R_FP5,R_FP6,
  100.          R_FP7,R_FPCR,R_SR,R_SSP,R_DFC,R_SFC,R_VBR,R_FPSR,
  101.          { other - not used in reg2str }
  102.          R_DEFAULT_SEG);
  103.  
  104.        { S_NO = No Size of operand }
  105.        { S_B  = Byte size operand  }
  106.        { S_W  = Word size operand  }
  107.        { S_L  = DWord size operand }
  108.        { USED FOR conversions in x86}
  109.        { S_BW = Byte to word       }
  110.        { S_BL = Byte to long       }
  111.        { S_WL = Word to long       }
  112.        { Floating point types      }
  113.        { S_X  = Extended type      }
  114.        { S_Q  = double/64bit integer }
  115.        { S_S  = single type (32 bit) }
  116.        topsize = (S_NO,S_B,S_W,S_L,S_BW,S_BL,S_WL,S_Q,S_S,S_X);
  117.  
  118.        plocation = ^tlocation;
  119.  
  120.        { information about the location of an operand }
  121.        { LOC_FPU         FPU registers = Dn if emulation }
  122.        { LOC_REGISTER    in a processor register }
  123.        { LOC_MEM         in the memory }
  124.        { LOC_REFERENCE   like LOC_MEM, but lvalue }
  125.        { LOC_JUMP        nur bool'sche Resultate, Sprung zu false- oder }
  126.        {                 truelabel }
  127.        { LOC_FLAGS       nur bool'sche Rsultate, Flags sind gesetzt }
  128.        { LOC_CREGISTER   register which shouldn't be modified }
  129.        { LOC_INVALID     added for tracking problems}
  130.  
  131.        tloc = (LOC_INVALID,LOC_FPU,LOC_REGISTER,LOC_MEM,LOC_REFERENCE,LOC_JUMP,
  132.            LOC_FLAGS,LOC_CREGISTER);
  133.  
  134.        tregisterlist = set of tregister;
  135.  
  136.  { F_E = Equal
  137.    F_NE = Not Equal
  138.    F_G = Greater then
  139.    F_L = Less then
  140.    F_GE = Greater or equal then
  141.    F_LE = Less or equal then
  142.    F_C = Carry
  143.    F_NC = Not Carry
  144.    F_A = Above
  145.    F_AE = Above or Equal
  146.    F_B = Below
  147.    F_BE = Below or Equal
  148.    other flags:
  149.    FL_xxx = floating type flags .
  150.  
  151.  }
  152.        tresflags = (F_E,F_NE,F_G,F_L,F_GE,F_LE,F_C,F_NC,
  153.           F_A,F_AE,F_B,F_BE);
  154.           { floating type flags used by FBCC are auotmatically converted }
  155.           { to standard condition codes                                  }
  156. {          FL_E,FL_NE,FL_A,FL_AE,FL_B,FL_BE);}
  157.  
  158.        preference = ^treference;
  159.  
  160.       { direction of address register : }
  161.       {              (An)     (An)+   -(An)  }
  162.       tdirection = (dir_none,dir_inc,dir_dec);
  163.  
  164.        treference = record
  165.       base,segment,index : tregister;
  166.       offset : longint;
  167.       symbol : pstring;
  168.       { indexed increment and decrement mode }
  169.       { (An)+ and -(An)                      }
  170.       direction : tdirection;
  171.       { a constant is also a treference, this makes the code generator }
  172.       { easier                                                         }
  173.       isintvalue : boolean;
  174.       scalefactor : byte;
  175.        end;
  176.  
  177.        tlocation = record
  178.       case loc : tloc of
  179.          { segment in reference at the same place as in loc_register }
  180.          LOC_REGISTER,LOC_CREGISTER : (register,segment : tregister);
  181.          LOC_MEM,LOC_REFERENCE : (reference : treference);
  182.          LOC_FPU : (fpureg:tregister);
  183.          LOC_JUMP : ();
  184.          LOC_FLAGS : (resflags : tresflags);
  185.          LOC_INVALID : ();
  186.        end;
  187.  
  188.        pcsymbol = ^tcsymbol;
  189.  
  190.        tcsymbol = record
  191.       symbol : pchar;
  192.          offset : longint;
  193.        end;
  194.  
  195.     const
  196.  {----------------------------------------------------------------------}
  197.  { F_E = Equal                                                          }
  198.  { F_NE = Not Equal                                                     }
  199.  { F_G = Greater then                                                   }
  200.  { F_L = Less then                                                      }
  201.  { F_GE = Greater or equal then                                         }
  202.  { F_LE = Less or equal then                                            }
  203.  { F_C = Carry                            = C                           }
  204.  { F_NC = Not Carry                       = not C